package com.health.record.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.health.common.annotation.Log;
import com.health.common.core.controller.BaseController;
import com.health.common.core.domain.AjaxResult;
import com.health.common.enums.BusinessType;
import com.health.record.domain.MedicalAppointmentDetail;
import com.health.record.service.IMedicalAppointmentDetailService;
import com.health.common.utils.poi.ExcelUtil;
import com.health.common.core.page.TableDataInfo;

/**
 * 预约Controller
 * 
 * @author ruoyi
 * @date 2025-10-30
 */
@RestController
@RequestMapping("/record/detail")
public class MedicalAppointmentDetailController extends BaseController
{
    @Autowired
    private IMedicalAppointmentDetailService medicalAppointmentDetailService;

    /**
     * 查询预约列表
     */
    @PreAuthorize("@ss.hasPermi('record:detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(MedicalAppointmentDetail medicalAppointmentDetail)
    {
        startPage();
        List<MedicalAppointmentDetail> list = medicalAppointmentDetailService.selectMedicalAppointmentDetailList(medicalAppointmentDetail);
        return getDataTable(list);
    }

    /**
     * 导出预约列表
     */
    @PreAuthorize("@ss.hasPermi('record:detail:export')")
    @Log(title = "预约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MedicalAppointmentDetail medicalAppointmentDetail)
    {
        List<MedicalAppointmentDetail> list = medicalAppointmentDetailService.selectMedicalAppointmentDetailList(medicalAppointmentDetail);
        ExcelUtil<MedicalAppointmentDetail> util = new ExcelUtil<MedicalAppointmentDetail>(MedicalAppointmentDetail.class);
        util.exportExcel(response, list, "预约数据");
    }

    /**
     * 获取预约详细信息
     */
    @PreAuthorize("@ss.hasPermi('record:detail:query')")
    @GetMapping(value = "/{detailId}")
    public AjaxResult getInfo(@PathVariable("detailId") Long detailId)
    {
        return success(medicalAppointmentDetailService.selectMedicalAppointmentDetailByDetailId(detailId));
    }

    /**
     * 新增预约
     */
    @PreAuthorize("@ss.hasPermi('record:detail:add')")
    @Log(title = "预约", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MedicalAppointmentDetail medicalAppointmentDetail)
    {
        return toAjax(medicalAppointmentDetailService.insertMedicalAppointmentDetail(medicalAppointmentDetail));
    }

    /**
     * 修改预约
     */
    @PreAuthorize("@ss.hasPermi('record:detail:edit')")
    @Log(title = "预约", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MedicalAppointmentDetail medicalAppointmentDetail)
    {
        return toAjax(medicalAppointmentDetailService.updateMedicalAppointmentDetail(medicalAppointmentDetail));
    }

    /**
     * 删除预约
     */
    @PreAuthorize("@ss.hasPermi('record:detail:remove')")
    @Log(title = "预约", businessType = BusinessType.DELETE)
	@DeleteMapping("/{detailIds}")
    public AjaxResult remove(@PathVariable Long[] detailIds)
    {
        return toAjax(medicalAppointmentDetailService.deleteMedicalAppointmentDetailByDetailIds(detailIds));
    }
}
